<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>librf: librf/src/awaitable.h 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">librf
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_3c80010775d22af2067790ecc9cdcf9d.html">librf</a></li><li class="navelem"><a class="el" href="dir_54ae0e78d997f6903cdf0996223d047f.html">src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">awaitable.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#pragma once</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160; </div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="keyword">namespace </span>resumef</div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;{</div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160; </div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;    <span class="keyword">template</span>&lt;<span class="keyword">class</span> _Ty&gt;</div>
<div class="line"><a name="l00012"></a><span class="lineno"><a class="line" href="structresumef_1_1awaitable__impl__t.html">   12</a></span>&#160;    <span class="keyword">struct </span><a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t</a></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;    {</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;        <span class="keyword">using</span> value_type = _Ty;</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;        <span class="keyword">using</span> <a class="code" href="structresumef_1_1state__t.html">state_type</a> = <a class="code" href="structresumef_1_1state__t.html">state_t&lt;value_type&gt;</a>;</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;        <span class="keyword">using</span> <a class="code" href="structresumef_1_1future__t.html">future_type</a> = <a class="code" href="structresumef_1_1future__t.html">future_t&lt;value_type&gt;</a>;</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;        <span class="keyword">using</span> lock_type = <span class="keyword">typename</span> <a class="code" href="structresumef_1_1spinlock.html">state_type::lock_type</a>;</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;        <span class="keyword">using</span> _Alloc_char = <span class="keyword">typename</span> state_type::_Alloc_char;</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160; </div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;        <a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t</a>() {}</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;        <a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t</a>(<span class="keyword">const</span> <a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t</a>&amp;) = <span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;        <a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t</a>(<a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t</a>&amp;&amp;) = <span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160; </div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;        <a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t</a>&amp; operator = (<span class="keyword">const</span> <a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t</a>&amp;) = <span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;        <a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t</a>&amp; operator = (<a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t</a>&amp;&amp;) = <span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160; </div>
<div class="line"><a name="l00031"></a><span class="lineno"><a class="line" href="structresumef_1_1awaitable__impl__t.html#a22f1adeb8ecfd2c078f620dbc7c368a1">   31</a></span>&#160;        <span class="keywordtype">void</span> <a class="code" href="structresumef_1_1awaitable__impl__t.html#a22f1adeb8ecfd2c078f620dbc7c368a1">set_exception</a>(std::exception_ptr e)<span class="keyword"> const</span></div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="keyword">        </span>{</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;            this-&gt;<a class="code" href="structresumef_1_1awaitable__impl__t.html#af7b6df5bbe7392334d7914db0d878915">_state</a>-&gt;set_exception(std::move(e));</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;            this-&gt;<a class="code" href="structresumef_1_1awaitable__impl__t.html#af7b6df5bbe7392334d7914db0d878915">_state</a> = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;        }</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160; </div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;        <span class="keyword">template</span>&lt;<span class="keyword">class</span> _Exp&gt;</div>
<div class="line"><a name="l00041"></a><span class="lineno"><a class="line" href="structresumef_1_1awaitable__impl__t.html#a2f7b2ef525186c9b7512dceb2453bebe">   41</a></span>&#160;        <span class="keywordtype">void</span> <a class="code" href="structresumef_1_1awaitable__impl__t.html#a2f7b2ef525186c9b7512dceb2453bebe">throw_exception</a>(_Exp e)<span class="keyword"> const</span></div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;<span class="keyword">        </span>{</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;            <a class="code" href="structresumef_1_1awaitable__impl__t.html#a22f1adeb8ecfd2c078f620dbc7c368a1">set_exception</a>(std::make_exception_ptr(std::move(e)));</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        }</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160; </div>
<div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="structresumef_1_1awaitable__impl__t.html#a647bd5f5a5572bbbe8a17000ea5dc06d">   49</a></span>&#160;        <a class="code" href="structresumef_1_1future__t.html">future_type</a> <a class="code" href="structresumef_1_1awaitable__impl__t.html#a647bd5f5a5572bbbe8a17000ea5dc06d">get_future</a>() noexcept</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;        {</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="structresumef_1_1future__t.html">future_type</a>{ this-&gt;<a class="code" href="structresumef_1_1awaitable__impl__t.html#af7b6df5bbe7392334d7914db0d878915">_state</a> };</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;        }</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160; </div>
<div class="line"><a name="l00057"></a><span class="lineno"><a class="line" href="structresumef_1_1awaitable__impl__t.html#af7b6df5bbe7392334d7914db0d878915">   57</a></span>&#160;        <span class="keyword">mutable</span> <a class="code" href="structresumef_1_1counted__ptr.html">counted_ptr&lt;state_type&gt;</a> <a class="code" href="structresumef_1_1awaitable__impl__t.html#af7b6df5bbe7392334d7914db0d878915">_state</a> = state_future_t::_Alloc_state&lt;state_type&gt;(<span class="keyword">true</span>);</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    };</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160; </div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    <span class="keyword">template</span>&lt;<span class="keyword">class</span> _Ty&gt;</div>
<div class="line"><a name="l00077"></a><span class="lineno"><a class="line" href="structresumef_1_1awaitable__t.html">   77</a></span>&#160;    <span class="keyword">struct </span>[[nodiscard]] <a class="code" href="structresumef_1_1awaitable__t.html">awaitable_t</a> : <span class="keyword">public</span> <a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t</a>&lt;_Ty&gt;</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    {</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;        <span class="keyword">using</span> <span class="keyword">typename</span> awaitable_impl_t&lt;_Ty&gt;::value_type;</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;        <span class="keyword">using</span> <a class="code" href="structresumef_1_1awaitable__impl__t.html">awaitable_impl_t&lt;_Ty&gt;::awaitable_impl_t</a>;</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160; </div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;        <span class="keyword">template</span>&lt;<span class="keyword">class</span> U&gt;</div>
<div class="line"><a name="l00089"></a><span class="lineno"><a class="line" href="structresumef_1_1awaitable__t.html#af66d4b4a3ba5339873b2dd8353ae6db3">   89</a></span>&#160;        <span class="keywordtype">void</span> <a class="code" href="structresumef_1_1awaitable__t.html#af66d4b4a3ba5339873b2dd8353ae6db3">set_value</a>(U&amp;&amp; value)<span class="keyword"> const</span></div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;<span class="keyword">        </span>{</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;            this-&gt;_state-&gt;set_value(std::forward&lt;U&gt;(value));</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;            this-&gt;_state = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;        }</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;    };</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160; </div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;<span class="preprocessor">#ifndef DOXYGEN_SKIP_PROPERTY</span></div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;    <span class="keyword">template</span>&lt;<span class="keyword">class</span> _Ty&gt;</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;    <span class="keyword">struct </span>[[nodiscard]] awaitable_t&lt;_Ty&amp;&gt; : <span class="keyword">public</span> awaitable_impl_t&lt;_Ty&amp;&gt;</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;    {</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;        <span class="keyword">using</span> <span class="keyword">typename</span> awaitable_impl_t&lt;_Ty&amp;&gt;::value_type;</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;        <span class="keyword">using</span> awaitable_impl_t&lt;_Ty&amp;&gt;::awaitable_impl_t;</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160; </div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;        <span class="keywordtype">void</span> set_value(_Ty&amp; value)<span class="keyword"> const</span></div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;<span class="keyword">        </span>{</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;            this-&gt;_state-&gt;set_value(value);</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;            this-&gt;_state = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;        }</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;    };</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160; </div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;    <span class="keyword">template</span>&lt;&gt;</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;    <span class="keyword">struct </span>[[nodiscard]] awaitable_t&lt;void&gt; : <span class="keyword">public</span> awaitable_impl_t&lt;void&gt;</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    {</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;        <span class="keyword">using</span> awaitable_impl_t&lt;void&gt;::awaitable_impl_t;</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160; </div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;        <span class="keywordtype">void</span> set_value()<span class="keyword"> const</span></div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;<span class="keyword">        </span>{</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;            this-&gt;_state-&gt;set_value();</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;            this-&gt;_state = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;        }</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;    };</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;<span class="preprocessor">#endif  //DOXYGEN_SKIP_PROPERTY</span></div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;}</div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="astructresumef_1_1awaitable__impl__t_html_a647bd5f5a5572bbbe8a17000ea5dc06d"><div class="ttname"><a href="structresumef_1_1awaitable__impl__t.html#a647bd5f5a5572bbbe8a17000ea5dc06d">resumef::awaitable_impl_t::get_future</a></div><div class="ttdeci">future_type get_future() noexcept</div><div class="ttdoc">获得与之关联的future_t&lt;&gt;对象，作为可等待函数(awaitable function)的返回值。</div><div class="ttdef"><b>Definition:</b> awaitable.h:49</div></div>
<div class="ttc" id="astructresumef_1_1future__t_html"><div class="ttname"><a href="structresumef_1_1future__t.html">resumef::future_t</a></div><div class="ttdoc">用于resumef协程的返回值。</div><div class="ttdef"><b>Definition:</b> future.h:14</div></div>
<div class="ttc" id="astructresumef_1_1awaitable__t_html"><div class="ttname"><a href="structresumef_1_1awaitable__t.html">resumef::awaitable_t</a></div><div class="ttdoc">用于包装‘异步函数’为‘可等待函数(awaitable function)’。</div><div class="ttdef"><b>Definition:</b> awaitable.h:77</div></div>
<div class="ttc" id="astructresumef_1_1awaitable__impl__t_html_a2f7b2ef525186c9b7512dceb2453bebe"><div class="ttname"><a href="structresumef_1_1awaitable__impl__t.html#a2f7b2ef525186c9b7512dceb2453bebe">resumef::awaitable_impl_t::throw_exception</a></div><div class="ttdeci">void throw_exception(_Exp e) const</div><div class="ttdoc">在协程内部，重新抛出之前设置的异常。</div><div class="ttdef"><b>Definition:</b> awaitable.h:41</div></div>
<div class="ttc" id="astructresumef_1_1awaitable__impl__t_html_a22f1adeb8ecfd2c078f620dbc7c368a1"><div class="ttname"><a href="structresumef_1_1awaitable__impl__t.html#a22f1adeb8ecfd2c078f620dbc7c368a1">resumef::awaitable_impl_t::set_exception</a></div><div class="ttdeci">void set_exception(std::exception_ptr e) const</div><div class="ttdoc">发生了异常后，设置异常。</div><div class="ttdef"><b>Definition:</b> awaitable.h:31</div></div>
<div class="ttc" id="astructresumef_1_1counted__ptr_html"><div class="ttname"><a href="structresumef_1_1counted__ptr.html">resumef::counted_ptr&lt; state_type &gt;</a></div></div>
<div class="ttc" id="astructresumef_1_1spinlock_html"><div class="ttname"><a href="structresumef_1_1spinlock.html">resumef::spinlock</a></div><div class="ttdoc">一个自旋锁实现。</div><div class="ttdef"><b>Definition:</b> spinlock.h:14</div></div>
<div class="ttc" id="astructresumef_1_1awaitable__impl__t_html"><div class="ttname"><a href="structresumef_1_1awaitable__impl__t.html">resumef::awaitable_impl_t</a></div><div class="ttdoc">awaitable_t&lt;&gt;的公共实现部分，用于减少awaitable_t&lt;&gt;的重复代码。</div><div class="ttdef"><b>Definition:</b> awaitable.h:12</div></div>
<div class="ttc" id="astructresumef_1_1awaitable__t_html_af66d4b4a3ba5339873b2dd8353ae6db3"><div class="ttname"><a href="structresumef_1_1awaitable__t.html#af66d4b4a3ba5339873b2dd8353ae6db3">resumef::awaitable_t::set_value</a></div><div class="ttdeci">void set_value(U &amp;&amp;value) const</div><div class="ttdoc">设置可等待函数的返回值。</div><div class="ttdef"><b>Definition:</b> awaitable.h:89</div></div>
<div class="ttc" id="astructresumef_1_1state__t_html"><div class="ttname"><a href="structresumef_1_1state__t.html">resumef::state_t</a></div><div class="ttdoc">专用于future_t&lt;&gt;的state类。</div><div class="ttdef"><b>Definition:</b> state.h:217</div></div>
<div class="ttc" id="astructresumef_1_1awaitable__impl__t_html_af7b6df5bbe7392334d7914db0d878915"><div class="ttname"><a href="structresumef_1_1awaitable__impl__t.html#af7b6df5bbe7392334d7914db0d878915">resumef::awaitable_impl_t::_state</a></div><div class="ttdeci">counted_ptr&lt; state_type &gt; _state</div><div class="ttdoc">管理的state_t&lt;&gt;对象。</div><div class="ttdef"><b>Definition:</b> awaitable.h:57</div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>
